package com.springbootblog.controller.fontend.thread;

public class TestDaemon
{
    public static void main(String[] args)
    {
        GOD god = new GOD();
        You you = new You();

        // 开启上帝线程
        Thread  thread = new Thread(god);
        // 设置守护线程
        thread.setDaemon(true);
        thread.start();

        // 开启人线程
        new Thread(you).start();

    }
}

/**
 * 上帝类（要指定为守护进程）
 */
class GOD implements Runnable
{
    @Override
    public void run()
    {
        while (true)
        {
            System.out.println(" GOD is protected you ! ");
        }
    }
}

/**
 * 人 类（要指定为用户进程）
 */
class You implements Runnable
{
    @Override
    public void run()
    {
        for (int i = 0; i < 365; i++)
        {
            System.out.println(" You is alive ! ");
        }
        System.out.println("bye bye this world!");
    }
}
